package com.assignwork.service.impl;

import com.assignwork.mapper.LineNoMapper;
import com.assignwork.service.ILineNoService;
import com.baomidou.dynamic.datasource.annotation.DS;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @ClassName LineNoServiceImpl
 * @Description
 * @Author dujianyu
 * @Date 2024/1/9 8:50
 */
@Service
@AllArgsConstructor
public class LineNoServiceImpl implements ILineNoService {

    LineNoMapper lineNoMapper;

    @Override
    @DS("master")
    public String getNewLineNo(LocalDate date) {
        Integer latestNoByDate = lineNoMapper.getLatestNoByDate(date);
        if (Func.isNull(latestNoByDate)) {
            latestNoByDate = 0;
        }
        String planDateStr = date.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        return planDateStr + String.format("%03d", latestNoByDate + 1);
    }
}
